# 导入包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入下拉框类，用于操作下拉框
from selenium.webdriver.support.select import Select

# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试的页面
url = 'file:///root/NSD2408/html/registerA.html'
driver.get(url)
"""
sleep(3)
# 定位option选项，然后点击
driver.find_element(By.CSS_SELECTOR, '[value="sh"]').click()
sleep(3)
driver.find_element(By.CSS_SELECTOR, '[value="gz"]').click()
sleep(3)
driver.find_element(By.CSS_SELECTOR, '[value="cq"]').click()
"""
el = driver.find_element(By.CSS_SELECTOR, '#selectA')
# 2.创建下拉框操作对象
select = Select(el)
# 3.使用下拉框操作对象切换选项
# 3.1 按照下标切换
# sleep(3)
# select.select_by_index(1)
# sleep(3)
# select.select_by_index(2)
# 3.2 按照value切换
# sleep(3)
# select.select_by_value('sh')
# sleep(3)
# select.select_by_value('cq')
# 3.3 按照可见文本
sleep(3)
select.select_by_visible_text('A上海')
sleep(3)
select.select_by_visible_text('A广州')

# 关闭浏览器
sleep(3)
driver.quit()